def loadDataSet():
    postingList = [['my', 'dog', 'has', 'flea','problems', 'tel', 'help', 'please'],
                ['maybe', 'not', 'take', 'him', 'to', 'dog', 'park','stupid'],
                ['my', 'dalmatian', 'is','so','I','the', 'dalmatian', 'I', 'love', 'him'],
                ['stop', 'posting','stupid', 'worthless','garbage','mr','licks', 'ate', 'my', 'steak','how','to','stop','him'],
                ['quit','buying','worthless', 'dog', 'food','stupid']]

    classVec = [0,1,0,1,0,1]
    return postingList,classVec

def createVocabList(dataSet):
    vocabSet =set([])
    for document in dataSet:
        vocabSet = vocabSet | set(document)
    return list(vocabSet)

def setOfWords2Vec(vocaList,inputSet):
    returnVec = [0] * len(vocaList)
    for word in inputSet:
        if word in vocaList:
            returnVec[vocaList.index(word)] = 1
        else:
            print("the word:%s is not in my voca list"% word)
    return returnVec

def trainNB0(trainMatrix,trainCategory):
    numExamples = len(trainMatrix)
    numWords = len(testWords)
    pAbusive = sum(trainCategory) / float(numExamples)
    p0Num = ones(numWords); p1Num = ones(numWords) # change to ones()
    p0Denom = 2.0; p1Denom = 2.0    # change to 2.0
    for i in range(numExamples):
        if (int(trainCategory[i]) == 1):
            p1Num +=trainMatrix[i]
            p1Denom += sum(trainMatrix[i])
        else:
            p0Num +=  trainMatrix[i]
            p0Denom += sum(trainMatrix[i] )
    p1Vect = log(p1Num / p1Denom)
    p0Vect = log(p0Num / p0Denom)
    return p0Vect,p1Vect,pAbusive
